Python Programming: Crash Course Tips & Tricks The Ultimate Guide for Beginners by James Anthony

Python Programming: Crash Course Tips & Tricks The Ultimate Guide for Beginners by James Anthony

Author:James , Anthony [James , Anthony]
Language: eng
Format: epub
Published: 2020-06-12T16:00:00+00:00


t

+ operat ori susedt o concatenat estri ngand*operat ori sa r epeti ti onoperat orfor st ri ng.

>>>s= " t omand "+" j er r y"

>>>p ri n t (s)

t omand j er r y

>>>s= " t h i s i s bad sp a m"* 3

>>>p ri n t (s)

T his i sbadspa mt his isbad s pamt hi s is ba dspa m

SlicingSt r ing

Youcantake subsetofst ri ngfr omori gi nalst ri ng byusi ng[ ]operat oral soknown assli ci ngoperat or .

Syn t ax: s[star t: end]

t his will r et ur npartofthe s tr ing st ar ti ngfr omindexst ar tt o i ndexend-1.

Let ’s take some exampl es .

>>>s= "We l come"

>>>s [ 1:3]

el

Somemor e exampl es .

>>>s= "We l come"

>>>s[:6]

'Wel com'

>>>s[4 : ]

'ome'

>>>s[1 : -1]

'elcom'

Note: start index and end index are optional. If omitted, then the default value of start index is 0 and that of end is the last index of the string.

Ord()a n dchr ( ) Fun c tions

or d()–f uncti on ret ur nst he ASCIIcodeof t he charact er .

chr()–f unct ion ret ur ns characterr epr esented bya ASC IInu mber .

>>> c h= ' b '

>>>o r d(ch)

98

>>>chr(97)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.